package com.xkstream.client.lgim;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.xkstream.client.application.Application;
import com.xkstream.client.entity.User;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.zip.GZIPOutputStream;

/**
 * Created by xiaoyi on 2018-1-15.
 */

public class LgMessageParser {
    private static final String KEY_CMMID = "cmmid";
    private static final String KEY_DATA = "data";
    private static final String KEY_EXTINFO = "extInfo";

    public static final int CODE_NORMAL = 310003;
    public static final int CODE_ENTER = 310001;
    public static final int CODE_GIFT = 310004;
    public static final int CODE_ONLINENUM = 310007;
    public static final int CODE_WIN = 100003; //盈利通知
    public static final int CODE_NOTIFICATION = 100001; //全平台公告


    public static LgMessage parser(JSONObject jsonObject) {
        if (jsonObject.has(KEY_CMMID)) {
            try {
                Gson gson = new Gson();
                return gson.fromJson(jsonObject.toString(), LgMessage.class);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return null;
    }


    public static String generateTextMessage(String content) {
        LgMessage message = new LgMessage();
        message.setCmmid(CODE_NORMAL);
        LgExtension extension = new LgExtension();
        extension.setContent(content);
        extension.setTo(2);
        message.setData(extension);
        return new Gson().toJson(message);
    }

    public static String generateEnterMessage(){
        String userCode = Application.getUser().getUser_code();
        LgMessage message = new LgMessage();
        message.setCmmid(CODE_ENTER);
        LgExtension extension = new LgExtension();
        extension.setAnchor_code(userCode);
        message.setData(extension);
        return new Gson().toJson(message);
    }
}
